/*****Log*****/
clear
cd "C:\Users\Joshua\Dropbox\Work\Networks and Economic Perceptions\Data and Do Files"
	/*the above needs to be updated to where you have the data/do files*/
	
log using "Appendix - PID Strength Analyses Output.smcl", replace
	/*the log file is in format .smcl, but can be read via txt editor*/

set more off


/***********************************************************************
************************************************************************
************************************************************************
This do file contains the needed to replicate the party identity strength
and ambivalence analyses found in the online appendix (Figure OA2 and Tables
OA6-OA9.

For each survey, the code will load and clean the data at hand using the
commands included in the survey cleaning .do files and then do the 
analyses in question. For those wishing to use this to replicate the analyses, 
you will need to update the cd command below to point to where your data
and .do files are located. 

Note: The disagreement measure is renamed for each data set below to
facil itate the coefplot graphing command

There are some STATA modules that need to be installed to run the following code: 

ssc install estout, replace
ssc install grc1leg, replace
ssc install coefplot, replace

Note: The analyses here were run using STATA 13. Users of STATA 15 
will likely get an error message when the esstab 
command below runs, specifically: 

	"equation / not found"

This is because of the "rename" function in the command seems to be 
broken in STATA 15. Deleting this line will fix matters. 


************************************************************************
************************************************************************
***********************************************************************/



/******************************************************
*******************************************************
		Figure OA2, Table OA6, Table OA7
*******************************************************
******************************************************/

/****************************************
*****************************************
		1992 CNEP
*****************************************
****************************************/	

/***************1992***********/
/*Data cleaning*/

clear
do "Data Cleaning - 1992 CNEP.do"
set more off


summ disagree_total, detail
	*5pct -4
	*95pct 3

/*Extremity*/
rename disagree_total disagree_1992

eststo clear
eststo: ologit pid_str_full c.disagree_1992 numgiven disc_knowl i.pid_2 news_att i.gender i.race age educ ///
			income i.marital
		
		estimates store CNEP_EXT
		

		 
/****************************************
*****************************************
		2002 ANES
*****************************************
****************************************/				 
		
*data cleaning
clear
do "Data Cleaning - 2002 ANES.do"
set more off

/*Extremity*/

rename disagree_total disagree_2000 

eststo:  ologit pid_str_full c.disagree_2000 names1 disc_knowl i.pid_2_2000 follow  ///
			i.gender i.race age2000 educ2000 income2000  i.marital2000 evaluate1 nfc1 [pweight=WT02PRE]
		
		estimates store AN2002_EXT

		

/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/	

*data cleaning
clear
do "Data Cleaning - 2006 ANES.do"
set more off
	
/*Extremity*/

rename disagree_total disagree_06

eststo: ologit pid_str_full c.disagree_06 names disc_interest i.pid_204 follow04   ///
			i.gender i.race age2004 educ income i.marital evaluate1 nfc1 [pweight = V06P002]
	
		estimates store AN2006_EXT


/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/	

clear
do "Data Cleaning - 2008 Panel.do"
set more off

/*Extremity*/
rename disagree_total disagree_10

eststo: ologit pid_str10_full c.disagree_10 numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC10]
		estimates store AN2008_10


rename disagree_10 disagree_11

eststo: ologit pid_str11_full c.disagree_11 numgiven1 network_interest i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]
		estimates store AN2008_11


rename disagree_11 disagree_17

eststo: ologit pid_str17_full c.disagree_17 numgiven1 network_interest i.pid_21 interest_w1 ///
			i.gender i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC17]
		
		estimates store AN2008_17

rename disagree_17 disagree_19

eststo: ologit pid_str19_full c.disagree_19 numgiven1 network_interest i.pid_21 interest_w1 i.gender ////
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC19]
		
		estimates store AN2008_19

		margins, at(disagree_19=(-3 3)) predict(outcome(4)) post 
		lincom 1._at - 2._at
		

/****Table for Extremity*/
esttab using TABLEOA2_PEXTREMITY.rtf, replace onecell label se pr2 nobaselevels star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("1992" "2002" "2006" "2008:Oct." "2008:Nov." "2009:May" "2009:July") ///
	title({\b Table OA2.} "Network Disagreement and Partisan Disagreement (OLOGIT)") ///
	rename(disagree_1992 Disagreement disagree_2000 Disagreement disagree_06 Disagreement disagree_10 Disagreement disagree_11 Disagreement disagree_17 Disagreement disagree_19 Disagreement) ///
	addnotes(OLOGIT Models. ANES Data is weighted: WT02PRE,V06P002, WGTC10, WGTC11, WGTC17, and WGTC19 respectively) 


/*Ambivalence*/
eststo clear

rename disagree_19 disagree_inlike
eststo: ologit in_like_w11  disagree_inlike  numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]
			
		estimates store AN2008_INL
		

rename disagree_inlike disagree_outdislike
eststo: ologit out_dislike_w11 disagree_outdislike  numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

		estimates store AN2008_OUTD

			
rename disagree_outdislike disagree_indislike
eststo: ologit in_dislike_w11 disagree_indislike   numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

		estimates store AN2008_IND

			
rename disagree_indislike disagree_outlike
eststo: ologit out_like_w11 disagree_outlike  numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

		estimates store AN2008_OUTL

/***Table for Ambivalence*/
esttab using TABLEOA3_PAMBIV.rtf, replace onecell label se pr2 aic bic star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("In-Party: Fav." "Out-Party: Unfav" "In-Party: Unfav" "Out-Party: Fav.") ///
			title({\b Table OA3.} "Network Disagreement and Partisan Ambivalence: 2008-2009 ANES Panel") ///
			rename(disagree_inlike Disagreement disagree_outdislike Disagreement disagree_indislike Disagreement disagree_outlike Disagreement) ///
			addnotes(OLOGIT Models. Data is weighted: WGTC11) 
	
eststo clear




/***Combined Coefplot*/
coefplot (CNEP_EXT, msymbol(C) pstyle(p5)) (AN2002_EXT, msymbo(C) pstyle(p5)) (AN2006_EXT, msymbol(C) pstyle(p5)) ///
	(AN2008_10, msymbol(C) pstyle(p5)) (AN2008_11, msymbol(C) pstyle(p5)) (AN2008_17, msymbol(C) pstyle(p5)) (AN2008_19, msymbol(C) pstyle(p5)) ///
	(AN2008_INL, msymbol(S) pstyle(p5)) (AN2008_OUTD, msymbol(S) pstyle(p5)) (AN2008_IND, msymbol(T) pstyle(p5)) ///
	(AN2008_OUTL, msymbol(T) pstyle(p5)), ///
	scheme(s1mono) legend(off) nooffsets keep(disagree_*) ///
	headings(disagree_1992="{bf:Extremity}" disagree_inlike="{bf:Ambivalence}") xline(0,lpattern(dash)) ///
	coeflabel(disagree_1992="1992 CNEP" disagree_2000="2002 ANES" disagree_06="2006 ANES" disagree_10="2008-2009 ANES:Oct. 08" ///
		disagree_11="2008-2009 ANES:Nov 08" disagree_17="2008-2009 ANES:May 09" ///
		disagree_19="2008-2009 ANES:July 09" ///
		disagree_inlike="In-Party:Fav." 	disagree_outdislike="Out-Party:Unfav." 	disagree_indislike="In-Party:Unfav." ///
		disagree_outlike="Out-Party:Fav.") ///
	groups(disagree_1992="N=801" disagree_2000="N=360" disagree_06="N=393" ///
		disagree_10="N=756" disagree_11="N=756" ///
		disagree_17="N=667" disagree_19="N=618" ///
		disagree_inlike="N=755" 	disagree_outdislike="N=751" ///
		disagree_indislike="N=686" 	disagree_outlike="N=754" , nogap angle(horizontal)) yscale(alt axis(2))  ///
	
graph save "Figure 1 - Partisan Extremity and Ambivalence", replace
graph export "Figure 1 - Partisan Extremity and Ambivalence.png", replace
graph export "Figure 1 - Partisan Extremity and Ambivalence.tif", replace

/*sub: out dislike*/
ologit out_like_w11 disagree_outlike  numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

	margins, at(disagree_outlike=(-3 3)) expression(predict(outcome(3)) + predict(outcome(4)) + predict(outcome(5)))
	
		
/******************************************************
*******************************************************
		Table OA8 and 9
*******************************************************
******************************************************/
		

		 
/****************************************
*****************************************
		2002 ANES
*****************************************
****************************************/				 
		
*data cleaning
clear
do "Data Cleaning - 2002 ANES.do"
set more off

/*Extremity*/

eststo clear
rename disagree_total disagree_2000 
eststo:  ologit pid_str_full c.disagree_2000 i.pid_str2000 names1 disc_knowl i.pid_2_2000 follow  ///
	i.gender i.race age2000 educ2000 income2000  i.marital2000 nfc1 evaluate1 [pweight=WT02PRE]
	
		
/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/	

*data cleaning
clear
do "Data Cleaning - 2006 ANES.do"
set more off

rename disagree_total disagree_06
eststo: ologit pid_str_full c.disagree_06 i.pid_str2004 names disc_interest i.pid_204 follow04   ///
	i.gender i.race age2004 educ income i.marital nfc1 evaluate1 [pweight = V06P002]

	
	

/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/	

clear
do "Data Cleaning - 2008 Panel.do"
set more off

/*Extremity*/
rename disagree_total disagree_10
eststo: ologit pid_str10_full c.disagree_10 i.pid_str1 numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
	i.race age educ income i.marital nfc1 evaluate1 [pweight= WGTC10]

rename disagree_10 disagree_11
eststo: ologit pid_str11_full c.disagree_11 i.pid_str1 numgiven1 network_interest i.pid_21 interest_w1 i.gender ///
i.race age educ income i.marital nfc1 evaluate1 [pweight= WGTC11]

rename disagree_11 disagree_17
eststo: ologit pid_str17_full c.disagree_17 i.pid_str1 numgiven1 network_interest i.pid_21 interest_w1 ///
i.gender i.race age educ income i.marital nfc1 evaluate1 [pweight= WGTC17]

rename disagree_17 disagree_19
eststo: ologit pid_str19_full c.disagree_19 i.pid_str1 numgiven1 network_interest i.pid_21 interest_w1 i.gender ////
	i.race age educ income i.marital nfc1 evaluate1 [pweight= WGTC19]

/*Table*/
esttab using TABLEOA4_EXTREMITY.rtf, replace onecell label se pr2 aic bic star(+ 0.10 * 0.05 ** 0.01) ///
		mtitles("2002 Panel" "2006 Pilot" "2008:W10" "2008:W11" "2008:W17" "2008:W19") ///
		title({\b Table OA4.} "Partisan Extremity and Network Disagreement - Controlling for Prior PID Extremity") ///
		rename(disagree_2000 Disagreement disagree_06 Disagreement disagree_10 Disagreement disagree_11 Disagreement disagree_17 Disagreement disagree_19 Disagreement) ///
		addnotes(OLOGIT MOdels. Data is weighted: WT02PRE,V06P002, WGTC10, WGTC11, WGTC17, and WGTC19 respectively) nobaselevels


/****Partisan Ambivalence****/


eststo clear

rename disagree_19 disagree_inlike
eststo: ologit in_like_w11  disagree_inlike in_like_w2 out_dislike_w2 in_dislike_w2 out_like_w2 numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]
			
rename disagree_inlike disagree_outdislike
eststo: ologit out_dislike_w11 disagree_outdislike in_like_w2 out_dislike_w2 in_dislike_w2 out_like_w2  numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

			
rename disagree_outdislike disagree_indislike
eststo: ologit in_dislike_w11 disagree_indislike in_like_w2 out_dislike_w2 in_dislike_w2 out_like_w2   numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

	
rename disagree_indislike disagree_outlike
eststo: ologit out_like_w11 disagree_outlike in_like_w2 out_dislike_w2 in_dislike_w2 out_like_w2 numgiven1 network_interest  i.pid_21 interest_w1 i.gender ///
			i.race age educ income i.marital evaluate1 nfc1 [pweight= WGTC11]

/***Table for Ambivalence*/
esttab using TABLEOA5_PAMBIV.rtf, replace onecell label se pr2 aic bic star(+ 0.10 * 0.05 ** 0.01) nobaselevels ///
			mtitles("In-Party: Fav." "Out-Party: Unfav" "In-Party: Unfav" "Out-Party: Fav.") ///
			title({\b Table OA3.} "Network Disagreement and Partisan Ambivalence: 2008-2009 ANES Panel") ///
			rename(disagree_inlike Disagreement disagree_outdislike Disagreement disagree_indislike Disagreement disagree_outlike Disagreement) ///
			addnotes(OLOGIT Models. Data is weighted: WGTC11) 
	
eststo clear




log close
